<template>
	<view class="order-views">
		<view class="grid-box">
			<view class="u-flex">
				<view class="u-m-r-20"><u-icon name="clock" size="80" :color="$u.color.infoDark"></u-icon></view>
				<view class="u-flex-1">
					<view class="head-title u-m-b-10"><text>{{orderForm.state}}</text></view>
					<view class="tips-txt"><text>请将入库所关联订单回收品送到站点</text></view>
				</view>
				<!-- <view class="">
					<u-image :src="orderForm.barcode" width="80rpx" mode="widthFix" @click="seePhoto(orderForm.barcode)"></u-image>
				</view> -->
			</view>
		</view>
		<view class="grid-box">
			<!-- <view class="head-title u-m-b-20"><text class="u-font-24">回收站点信息</text></view> -->
			<view class="u-flex">
				<view class="u-flex-1">
					<view class="msg-box">
						<view class="item u-m-b-5">
							<view class="u-font-36">{{orderForm.store.name}}</view>
						</view>
						<view class="item">
							<view class="u-font-28 u-tips-color"><u-icon name="phone-fill"></u-icon>{{orderForm.store.mobile}}</view>
						</view>
					</view>
				</view>
				<view>
					<u-button type="primary" size="mini" @click="tel(orderForm.store.mobile)">联系站点</u-button>
				</view>
			</view>
		</view>
		<view class="grid-box">
			<view class="head-title u-m-b-10"><text>关联订单</text></view>
			<u-cell-group class="u-m-t-20">
				<u-cell-item :title="item.number" v-for="(item, index) in orderForm.userorders" :key="item.id" @click="detailsOrder(item.id)" class="u-p-r-0 u-p-l-0">
				</u-cell-item>
			</u-cell-group>
		</view>
		<view class="grid-box" v-if="orderForm.make.length > 0">
			<view class="u-table-box">
				<view class="head-title u-m-b-20"><text>关联订单回收品类</text></view>
				<!-- <view v-for="(item,index) in orderForm.make" :key="index">
					<view class="u-m-b-10 u-m-t-10"><text>{{item.typenames}}</text></view>
					<u-table>
						<u-tr>
							<u-th>类型</u-th>
							<u-th>重量(KG)</u-th>
						</u-tr>
						<u-tr v-for="(cell,i) in item.details" :key="i">
							<u-td>{{cell.typenames}}</u-td>
							<u-td>{{cell.originalweight}}</u-td>
						</u-tr>
					</u-table>
				</view> -->
				
				<!-- <goods-list :orderId="id" :make="orderForm.make" :state="orderForm.state"></goods-list> -->
				<goods-table :details="confirmForm.details"></goods-table>
			</view>
			<!-- <view class="total">
				<text>订单金额：</text>
				<text class="total-price">
					￥{{orderForm.userorderamount.toFixed(2)}}
				</text>
			</view> -->
			<!-- <view class="total">
				<text>预计佣金：</text>
				<text class="total-price">
					￥{{(orderForm.userorderamount*0.1).toFixed(2)}}
				</text>
			</view> -->
		</view>
		<view class="grid-box">
			<view class="head-title u-m-b-20"><text>订单信息</text></view>
			<view class="msg-box">
				<view class="item">
					<text class="label">订单编号：</text>
					<view class="text">{{orderForm.number}}</view>
				</view>
				<view class="item">
					<text class="label">下单时间：</text>
					<view class="text">{{$u.timeFormat(orderForm.createddatetime, 'yyyy-mm-dd hh:MM:ss')}}</view>
				</view>
				<view class="item" v-if="orderForm.remarks">
					<text class="label">入库单备注：</text>
					<view class="text">{{orderForm.remarks}}</view>
				</view>
			</view>
		</view>
		<view class="navigation">
			<view class="right">
				<!-- <u-button class="navbtn">联系客服</u-button> -->
				<view class="u-p-r-30" @click="showCancel = true"><text style="text-decoration: underline;">取消入库</text></view>
				<view class="u-flex-1">
					<u-button class="navbtn" @click="back">返回列表</u-button>
				</view>
				<!-- <u-button type="error" class="navbtn" @click="showCancel = true">取消入库</u-button> -->
			</view>
		</view>
		<!-- 取消入库 -->
		<u-popup v-model="showCancel" mode="center" border-radius="14" z-index="999" closeable>
			<view class="u-p-40" style="width: 600rpx;">
				<view class="u-p-t-30 u-p-b-15">请填写取消入库原因：</view>
				<view class="u-p-b-30">
					<u-input v-model="cancelForm.reason" type="textarea" :border="true" />
				</view>
				<u-button type="error" class="navbtn" @click="cancelOrder">确定</u-button>
			</view>
		</u-popup>
		<!-- 选择站点 -->
		<u-popup v-model="show1" mode="bottom" border-radius="14" length="80%">
			<storeList @confirm="confirm" @close="close"></storeList>
		</u-popup>
	</view>
</template>

<script>
	import storeList from './storeList.vue'
	
	export default {
		components:{
			storeList
		},
		props:{
			orderId: 0,
			orderForm: {}
		},
		data() {
			return {
				show1: false,
				showCancel: false,
				cancelForm: {
					id: 0,
					reason: ""
				},
				confirmForm:{
					details:[]
				}
			}
		},
		created() {
			this.orderForm.make.forEach((item)=>{
				item.details.forEach((cell)=>{
					this.confirmForm.details.push({
						"show": false,
						"id": cell.productid,
						"price": cell.price,
						"weight": cell.originalweight,
						"amount": cell.amount,
						"typeremarks": cell.remarks,
						"allowedit": true,
						"minprice": 0,
						"highprice": 0,
						"err": false,
						"typenames": item.names,
						"name": cell.productname,
						"isweighing": cell.isweighing,
						"typeid": item.id,
						"pic": item.icon,
						"on": true
					})
				})
			})
		},
		methods: {
			// 查看地图
			goMap(lat,lng){
				// uni.navigateTo({
				// 	url: `/pages/brother/order/views/map/map?lat=${lat}&lng=${lng}`
				// })
				
				uni.openLocation({
					latitude: lat,
					longitude: lng,
					name: this.orderForm.store.name,
					address: this.orderForm.store.address,
					success: function () {
						console.log('success');
					}
				});
			},
			// 取消入库
			cancelOrder(){
				uni.showModal({
					title: '提示',
					content: '您确定要取消入库吗?',
					success: (res) => {
						if (res.confirm) {
							this.cancelForm.id = this.orderId
							this.$u.post('/Store/InOrder/Cancel',this.cancelForm).then((res)=>{
								uni.showToast({
									icon: 'none',
									title: res.msg
								})
								this.showCancel = false
								this.$emit('update')
							})
						}
					}
				})
			},
			// 订单详情
			detailsOrder(id){
				uni.navigateTo({
					url: '/pages/brother/order/views/views?id='+id
				})
			},
			// 获取返回站点
			confirm(item){
				this.show1 = false
				
				this.$u.get('/Store/InOrder/ChangeStore',{
					id:this.orderId,
					storeId: item.id
				}).then((res)=>{
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
					this.$emit('update')
				})
			},
			// 关闭窗口
			close(state){
				this.show1 = state
			},
			seePhoto(url){
				let img = this.fileURL + url
				uni.previewImage({
					current: 0,
					urls: [img]
				});
			},
			tel(number){
				uni.makePhoneCall({
					phoneNumber: number
				})
			},
			back(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.order-views{
		// min-height: 100vh;
	}
	.u-color-orange{
		color: $u-color-orange;
	}
	// 宫格展示
	.grid-box {
		background-color: #fff;
		margin: 0 30rpx;
		padding: 30rpx;
		border-radius: 24rpx;
		margin-top: 30rpx;
		box-shadow: $u-color-border-shadow;
		.head-title{
			font-size: 32rpx;
			display: flex;
			justify-content: space-between;
			.more{
				color: $u-color-blue;
			}
		}
		.tips-txt{
			color: $u-tips-color;
			font-size: 24rpx;
		}
	}
	// 订单
	.order {
		// width: 690rpx;
		// background-color: #ffffff;
		// margin: 30rpx auto;
		// border-radius: 30rpx;
		// box-sizing: border-box;
		// padding: 30rpx;
		// font-size: 28rpx;
		// box-shadow: $u-color-border-shadow;
		.top {
			display: flex;
			justify-content: space-between;
			.left {
				display: flex;
				align-items: center;
				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}
			.right {
				color: $u-type-warning-dark;
			}
		}
		.item {
			display: flex;
			margin: 20rpx 0 0;
			justify-content: space-between;
			.left {
				margin-right: 20rpx;
				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 10rpx;
				}
			}
			.content {
				.title {
					font-size: 28rpx;
					line-height: 50rpx;
				}
				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}
				.delivery-time {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;
				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}
				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}
		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;
			.total-price {
				font-size: 32rpx;
				color: $u-color-orange;
			}
		}
		.time{
			font-size: 24rpx;
			margin: 20rpx 0;
			line-height: 40rpx;
		}
		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;
			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
				padding: 0 10rpx;
			}
			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}
	// 按钮栏
	.navigation {
		display: flex;
		margin-top: 30rpx;
		border: solid 2rpx #f2f2f2;
		background-color: #ffffff;
		position: sticky;
		bottom: 0;
		z-index: 99;
		.right {
			display: flex;
			font-size: 28rpx;
			align-items: center;
			flex: 1;
			justify-content: space-around;
			padding: 20rpx;
			.navbtn{
				width: 100%;
				margin: 0 10rpx;
			}
			.btn {
				line-height: 66rpx;
				padding: 0 30rpx;
				border-radius: 36rpx;
				color: #ffffff;
				margin: 16rpx 0;
			}
			.cancel {
				margin-right: 30rpx;
				color: $u-tips-color;
			}
			.buy {
				background-color: #ff7900;
			}
		}
	}
	// 
	.u-table-box{
		margin: 20rpx 0;
		.green{
			background-color: $u-color-green;
			color: #fff!important;
		}
		.red{
			background-color: $u-color-red;
			color: #fff!important;
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
			color: $u-color-orange;
		}
	}

	.u-line{
		border-bottom: 1px solid $u-border-color;
		padding-top: 30rpx;
		margin-bottom: 20rpx;
	}
</style>
